
program simpson
    implicit none
    real a,b,h,s,x,f1,f2,f
    f(x)=sin(x)+cos(x)
    integer n,i
    i=1

    print *, 'integral of sin(x)+cos(x), please input a,b and n'
    read(* ,*) a,b,n
    h=(b-a)/(2.0*n)
    s=0.0
    x=a+h
    f2=0.0
    f1=f(x)

    do 10, i=1,n-1
        x=x+h
        f2=f2+f(x)
        x=x+h
        f1=f1+f(x)
10 continue

    s=h/3.0*(f(a)+f(b)+4*f1+2*f2)
    print *, 'integral of f(x)=', s

end program

